package com.SmartCare.service.impl.health;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.SmartCare.common.Result;
import com.SmartCare.mapper.health.LaboratoryRecordMapper;
import com.SmartCare.pojo.health.LaboratoryRecord;
import com.SmartCare.service.health.LaboratoryRecordService;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class LaboratoryRecordServiceImpl extends ServiceImpl<LaboratoryRecordMapper, LaboratoryRecord> implements LaboratoryRecordService {
    @Override
    public Result addLoadVideoReport(Long elderId, String laboratoryUrl, Date testTime) {
        LambdaQueryWrapper<LaboratoryRecord> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(LaboratoryRecord::getElderId,elderId);
        wrapper.eq(LaboratoryRecord::getLaboratoryUrl,laboratoryUrl);
        wrapper.eq(LaboratoryRecord::getTestingTime,testTime);

        LaboratoryRecord one = getOne(wrapper);
        if (one!=null){
            return Result.error("记录已添加,请勿重复添加");
        }

        LaboratoryRecord record = LaboratoryRecord.builder()
                .elderId(elderId)
                .laboratoryUrl(laboratoryUrl)
                .testingTime(testTime)
                .build();
        boolean res = save(record);
        if (res)
            return Result.success("添加成功");
        return Result.error("添加失败");
    }

}
